#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.65])
AC_INIT([xy], [2011], [https://enter.bugs.here])
AM_INIT_AUTOMAKE([dist-bzip2])
AM_MAINTAINER_MODE
AC_CONFIG_SRCDIR([src])
AC_CONFIG_HEADERS([config.h])

CFLAGS="-std=c99 -O0 -g3 -Wall -Wunused -Wextra -Wno-unused-parameter"

AM_PROG_CC_C_O
AC_PROG_RANLIB

AC_PATH_X

PKG_CHECK_MODULES([XLIB], [x11])
PKG_CHECK_MODULES([XINERAMA], [xinerama])
PKG_CHECK_MODULES([XFT], [xft])

PKG_CHECK_MODULES([LIBUSB], [libusb])

AC_CHECK_LIB(xosd, xosd_create)
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_HEADERS(xosd.h)

AC_CHECK_LIB(log4c, log4c_init)
AC_CHECK_HEADERS(log4c.h)

AC_ARG_ENABLE(optimizations,
    AS_HELP_STRING([--enable-optimizations],
                   [Enable compiler optimizations (defaults to disabled)]),
    [optimize=yes],[optimize=no])

if test "x$optimize" == "xyes"; then
    CFLAGS="-std=c99 -O3 -Wall -Wunused -Wextra -Wno-unused-parameter"
else
    CFLAGS="-std=c99 -O0 -g3 -Wall -Wunused -Wextra -Wno-unused-parameter"
fi

AC_ARG_ENABLE(tests,
    AS_HELP_STRING([--enable-tests],
                   [Enables unit tests (defaults to disabled)]),
    [testing=yes],[testing=no])

if test "x$testing" == "xyes"; then
    PKG_CHECK_MODULES(CHECK, [check >= 0.9.8], have_check="yes", have_check="no")
else
    have_check=no
fi

if test "x$testing" == "xyes" -a "x$have_check" != "xyes"; then
    AC_MSG_ERROR([Testing dependencies not met. Check is required.])
fi
AM_CONDITIONAL(TESTING, test "x$have_check" = "xyes")

AC_TYPE_SIZE_T

AC_CONFIG_FILES([
                 Makefile
                 docs/Makefile
                 lib/Makefile
                 src/Makefile
                 tests/Makefile
])

AC_OUTPUT

printf "
xy build configuration
----------------------
version         : ${VERSION}
cflags          : ${CFLAGS}
tests           : ${testing}
optimizations   : ${optimize}
"
